<?php
    date_default_timezone_set('Asia/Ho_Chi_Minh');
    class Controller extends CController
    {    
        public $metaTitle;            
        public $metaKeywords;         
        public $metaDescription;     

        public $google_verify;      
        public $bing_verify;  
        public $alexa_verify;  
        public $google_plus;

        public $metaIndex;      
        public $metaFollow;      
        public $linkCanoncical;       
        public $menuUserActive;        
        public $headerActive; 
        // ducnv
        public $shop_config;
        public $is_index;  
        public $domain;                     
        public $breadcrumbs=array(); 

        public function getBreadcrumbs(){
            $breadcrumbs = $this->breadcrumbs;
            $str = '<strong><a href="'.Yii::app()->baseUrl.'"><span class="trang">Home</span></a> » '; 
            foreach($breadcrumbs as $key=>$value){
                if(isset($value["name"]) && isset($value["link"]) && isset($value["class"])){              
                    $str .= '<a href="'.$value["link"].'"><span class="trang">'.$value["name"].'</span></a> » </strong>';                
                }
            } 
            return $str;                                       
        }
        public function beforeAction($action)
        {   
            $path = $_SERVER['HTTP_HOST'];

            $userInfo = User::getUserIdByDomain($path);
            if(!empty($userInfo)){
                $_SESSION['username'] = $userInfo['user_name'];
                $_SESSION['userId'] = $userInfo['user_id']; 
            }else{
                if (strpos($path,'.')!=FALSE)
                {
                    $path = explode('.',$path);
                    $domain = $path[1];
                    $subdomain = $path[0];
                } else {
                    $path=''; 
                } 
                $_SESSION['username']=$subdomain;
                $_SESSION['userId']= User::getUserId($_SESSION['username']) ;
                if(empty($_SESSION['userId'])){
                    $_SESSION['userId']=2455;
                }

            }
            return true;
        }

        public function createImage($location, $ufile)
        {
            $filename = "";        
            $image = @imagecreatefromstring($ufile["image_data"]);

            if($ufile["extension"]=="png")
            {
                $filename = $ufile["filename"] . "." . "png";
                $result = @imagepng($image, $location . $filename, 100);              
            } 
            else if($ufile["extension"]=="gif")
                {
                    $filename = $ufile["filename"] . "." . "gif";      
                    $result = @imagegif($image, $location . $filename, 100);
                } 
                else 
                {
                    $filename = $ufile["filename"] . "." . "jpg";
                    $result = @imagejpeg($image, $location . $filename, 100);  
            }              

            return $filename;
        }
    }
?>
